﻿using log4net;
using System;
using System.Threading;

namespace ZKDevice
{
    static class Program
    {
        private static ILog log = LogManager.GetLogger(typeof(Program));
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            string ip = "192.168.2.203";
            int port = 4370;
            ZKDeviceAPI zkDevice = new ZKDeviceAPIImpl();
            bool connect = zkDevice.Connect(ip, port);
            while (!connect)
            {
                log.WarnFormat("连接失败，正在尝试重新连接 {0}:{1}", ip, port);
                Thread.Sleep(5000);
                connect = zkDevice.Connect(ip, port);
            }
            log.InfoFormat("连接成功 {0}:{1}", ip, port);
            UserInfo userInfo = new UserInfo();
            userInfo.identifier = 10001;
            userInfo.name = "潘明智";
            bool downloadUserInfo = zkDevice.DownloadUserInfo(userInfo);
            if (!downloadUserInfo)
            {
                log.WarnFormat("下载失败，正在尝试重新下载。编号：{0}", userInfo.identifier);
                Thread.Sleep(5000);
                downloadUserInfo = zkDevice.DownloadUserInfo(userInfo);
            }
            zkDevice.DisConnect();
            log.InfoFormat("下载成功。编号：{0}", userInfo.identifier);
            log.Info("结束任务,系统退出");
        }
    }
}
